﻿using DevTeam;

using System;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo
{
    public partial class DesenAra : XPopupForm
    {
        public DesenAra()
        {
            InitializeComponent();
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            //gvProduct.VeriyiGuncelle("FindSimilarByDesen", txtStokKodu.EditValue);
            //gvProduct.BestFitColumns();
            //timer.Stop();
        }

        private void txtDesenNo_EditValueChanged(object sender, EventArgs e)
        {
            //timer.Stop();
            //timer.Start();

            gvProduct.RefreshDataSource("FindSimilarByDesen", txtStokKodu.EditValue);
            gvProduct.BestFitColumns();
        }

        private void DesenAra_Load(object sender, EventArgs e)
        {

            BindingSource bs = gvProduct.Init("FindSimilarByDesen", txtStokKodu.EditValue);
            bs.CurrentChanged += new EventHandler(bs_CurrentChanged);
            gvProduct.FormatAsPercentage("Score");
            gvProduct.SetCaptions("Scan:Foto");
            gvProduct.MakeRowSelectable();
            gvProduct.MakeReadOnly();
            gvProduct.AddSummary();
            gvProduct.DoubleClick += gvProduct_DoubleClick;
            btnKartAc.ItemClick += btnKartAc_ItemClick;
            txtStokKodu.EditValueChanged += txtDesenNo_EditValueChanged;
            gvProduct.BestFitColumns();

        }

        void btnKartAc_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DesenNo = txtStokKodu.EditValue.ToStr();
            if (DesenNo.Contains("_") && !DesenNo.Contains("/"))
            {
                ShowMessage("DesenNo ve rengi ayırmak için _ yerine / kullanın.");
                return;
            }

            DialogResult = DialogResult.No;
        }

        void bs_CurrentChanged(object sender, EventArgs e)
        {
            gvProduct.BestFitColumns();
        }

        public string DesenNo { get; set; }
        public int ProductId { get; set; }

        private void gvProduct_DoubleClick(object sender, EventArgs e)
        {
            ProductId = gvProduct.GetFocusedDataRow()["ProductId"].ToInt(-1);
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }

    }
}